import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import java.io.IOException;


/*
 * URL重写
 * */
@WebServlet("/e")
public class ServletE extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 获取或创建一个新的会话
        HttpSession session = request.getSession(true);
        session.setAttribute("s1","aaaaa");

        // 假设我们有一个目标URL
        String targetUrl = request.getContextPath() + "/f";
        String encodedUrl = response.encodeRedirectURL(targetUrl); // ✅ 正确方法
        response.sendRedirect(encodedUrl); // 通常配合重定向使用
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
